package com.cqupt.controller;

import com.cqupt.model.pojo.Word;
import com.cqupt.model.pojo.WordUnknown;
import com.cqupt.model.vo.Result;
import com.cqupt.model.vo.ResultCodeEnum;
import com.cqupt.model.vo.WordVO;
import com.cqupt.service.UserWordService;
import com.cqupt.service.WordUnknownService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/userWord")
@Tag(name = "用户单词模块")
public class UserWordController {

    @Resource
    private UserWordService userWordService;

    @Resource
    private WordUnknownService wordUnknownService;


//    @GetMapping("/unknown")
//    @Operation(summary = "不认识的单词添加到生词本")
//    public Result unknown(@RequestParam int wordId, @RequestParam int bookId) {
//        userWordService.unknown(wordId, bookId);
//        return Result.build(null, ResultCodeEnum.SUCCESS);
//    }


    @GetMapping("/unknown")
    @Operation(summary = "不认识的单词添加到生词本")
    public Result unknown(@RequestParam int wordId, @RequestParam int bookId) {
        wordUnknownService.unknown(wordId, bookId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/cancel")
    @Operation(summary = "将单词从单词本删除")
    public Result cancel(@RequestParam int wordId, @RequestParam int bookId) {
        wordUnknownService.cancel(wordId, bookId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

//    @GetMapping("/allUnknown")
//    @Operation(summary = "获取所有生词本单词")
//    public Result getAllUnknown() {
//        List<Word> all = userWordService.getAllUnknown();
//        return Result.build(all, ResultCodeEnum.SUCCESS);
//    }

    @GetMapping("/allUnknown")
    @Operation(summary = "获取所有生词本单词")
    public Result getAllUnknown() {
        List<Word> all = wordUnknownService.getAllUnknown();
        return Result.build(all, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/ismark")
    @Operation(summary = "判断单词是否加入生词本")
    public Result ismark(@RequestParam Integer wordId) {
        WordVO wordVO = wordUnknownService.ismark(wordId);
        return Result.build(wordVO, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/getLearn")
    @Operation(summary = "获取生词本中已经学过的单词")
    public Result getLearn() {
        List<Word> all = wordUnknownService.getLearn();
        return Result.build(all, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/getUnLearn")
    @Operation(summary = "获取生词本中未学过的单词")
    public Result getUnLearn() {
        List<Word> all = wordUnknownService.getUnLearn();
        return Result.build(all, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/getIsKnown")
    @Operation(summary = "获取生词本标熟的单词")
    public Result getIsKnown() {
        List<Word> all = wordUnknownService.getIsKnown();
        return Result.build(all, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/mark")
    @Operation(summary = "将生词本的单词标记为熟悉")
    public Result mark(@RequestParam int wordId) {
        wordUnknownService.mark(wordId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/unmark")
    @Operation(summary = "将生词本的单词取消标熟")
    public Result unmark(@RequestParam int wordId) {
        wordUnknownService.unmark(wordId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/allLearned")
    @Operation(summary = "获取所有学习过的单词")
    public Result getAllLearned(int bookId) {
        List<Word> all = userWordService.getAllLearned(bookId);
        return Result.build(all, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/rest")
    @Operation(summary = "休息一下")
    public Result rest(@RequestParam int bookId,@RequestParam int count) {
        userWordService.rest(bookId,count);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/again")
    @Operation(summary = "再来一组")
    public Result again(@RequestParam int bookId,@RequestParam int count) {
        List<Word> list = userWordService.again(bookId,count);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

}
